@extends('admin.base')
@section('title', '添加商品')
@section('content')
<div class="layui-card">
    <fieldset class="layui-elem-field">
        <div class="layui-field-box">
            <span class="layui-breadcrumb" lay-separator=">>">
                <a class="layui-btn-sm" href="{{url('admin/role/index')}}" style="cursor:pointer;" >商品列表</a>;
                <a class="layui-btn-sm" href="" style="cursor:pointer;" ><cite>添加</cite></a>
                <!-- <a><cite>正文</cite></a> -->
            </span>
        </div>
    </fieldset>

    <div class="layui-card-body">
        <form class="layui-form layui-form-pane" method="post" action="{{url('/admin/shop/insert')}}">
            @csrf
            <div class="layui-form-item">
                <label class="layui-form-label">商品名</label>
                <div class="layui-input-inline" style="width:30%;">
                    <input type="type" name="name" value='' required lay-verify="required" placeholder='请输入商品名' autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">主图</label>
                <button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件</button>
                <input type="hidden" name="picname" id="picname">
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">分类</label>
                <div class="layui-input-inline" style="width:30%;">
                    <select id="sub_pid" name="tid" lay-verify="" lay-search >
                        <option value="">==请选择==</option>
                        @foreach($all_list as $fvo)
                            <option value="{{$fvo->id}}" @if($fvo->is_exit == 1)disabled="disabled" @endif><?php echo str_repeat("&nbsp;",substr_count($fvo->path,',')*3);?>|--{{$fvo->name}}</option>
                        @endforeach
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux"></div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">品牌</label>
                <div class="layui-input-inline" style="width:30%;">
                    <select id="sub_pid" name="bid" lay-verify="" lay-search >
                        <option value="0">==请选择==</option>
                        @foreach($all_list2 as $fvo)
                            <option value="{{$fvo->id}}" @if($fvo->is_exit == 1) disabled="disabled" @endif><?php echo str_repeat("&nbsp;",substr_count($fvo->path,',')*3);?>|--{{$fvo->name}}</option>
                        @endforeach
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux"></div>
            </div>

            <div class="layui-form-item">

                <label class="layui-form-label">规格组合</label>
                <div class="layui-input-block">
                    <input type="radio" name="is_attr" value="0" title="无" checked>
                    <input type="radio" name="is_attr" value="1" title="有" >
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">规格类型</label>
                <div class="layui-input-inline" style="width:30%;">
                    <select id="sub_pid" name="attrtype_id" lay-verify="" lay-search >
                        <option value="">==请选择==</option>
                        @foreach($all_list3 as $fvo)
                            <option value="{{$fvo->id}}">|--{{$fvo->tname}}</option>
                        @endforeach
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">成本价</label>
                <div class="layui-input-inline" style="width:30%;">
                    <input type="type" name="cost_price" value='' required lay-verify="required" placeholder='请输入成本价' autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">销售价</label>
                <div class="layui-input-inline" style="width:30%;">
                    <input type="type" name="sell_price" value='' required lay-verify="required" placeholder='请输入销售价' autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">销量</label>
                <div class="layui-input-inline" style="width:30%;">
                    <input type="type" name="sale_num" value='0' required lay-verify="required" placeholder='请输入销量' autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-inline" style="width:30%;">
                    <input type="type" name="sort" value='0' required lay-verify="required" placeholder='请输入排序' autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux">数字越大,显示越靠前</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">内容:</label>
                <div class="layui-input-block">
                    <textarea id="demo" style="display: none;" name="content"></textarea>
                </div>
            </div>

            {{--<div class="layui-form-item layui-form-text" >--}}
                {{--<div class="layui-input-block" >--}}
            {{--<textarea name="content" id="content">--}}

            {{--</textarea>--}}
                {{--</div>--}}
            {{--</div>--}}

            <div class="layui-form-item">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </form>
    </div>
</div>
@endsection
@section('js')
<script type="text/javascript">

    {{--layui.use(['layedit','form'], function(){--}}
        {{--let form = layui.form;--}}
        {{--form.render();--}}

        {{--var index = layedit.build('demo'); //建立编辑器--}}
        {{--var form = layui.form;--}}
        {{--var layedit = layui.layedit;--}}
        {{--//监听提交--}}
        {{--//添加--}}
        {{--form.on('submit(formDemo)', function(data){--}}
            {{--var aa = layedit.getContent(index);--}}
            {{--data.field.content = aa;--}}
            {{--layer.confirm('确认执行此操作？', {icon: 3, title:'提示'}, function(index){--}}
                {{--ajax("{{url('admin/shop/insert')}}",data.field, function(data){--}}
                    {{--layer.close();--}}
                    {{--layer.closeAll();--}}
                    {{--layer.msg(data.msg);--}}
                    {{--if(data.code == 1){--}}
                        {{--location.href = '/admin/shop/index';--}}
                    {{--}--}}
                {{--});--}}
            {{--});--}}
            {{--return false;--}}
        {{--});--}}
    {{--});--}}

    layui.use(['layedit','form'],
        function() {
            var layedit = layui.layedit;
            layedit.set({
                uploadImage: {
                    url: '/admin/shop_editor',
                    type: 'post'
                }
            });
            var index = layedit.build('demo'); //建立编辑器
            var form = layui.form;
            var layedit = layui.layedit;

            //监听提交
            form.on('submit(formDemo)', function(data){
                var aa = layedit.getContent(index);
                data.field.contents = aa;
                layer.confirm('确认执行此操作？', {icon: 3, title:'提示'}, function(index){
                    ajax("{{url('admin/shop/insert')}}",data.field,function(data){
                        layer.close();
                        layer.closeAll();
                        layer.msg(data.msg);
                        if(data.code == 1){
                            location.href = '/admin/shop/index';
                        }
                    });
                });
                return false;
            });
        });

    // layui.use('layedit', function(){
    //     var layedit = layui.layedit;
    //     layedit.build('demo'); //建立编辑器
    // });

    layui.use('upload',function(){
        var $ = layui.jquery
            ,upload = layui.upload;
        //指定允许上传的文件类型
        upload.render({
            elem: '#test3'
            ,url: '/admin/shop_up' //改成您自己的上传接口
            ,accept: 'file' //普通文件
            ,done: function(res){
                layer.msg(res.msg);
                if(res.code == 1){
                    $("#test3").text('上传成功!');
                    $("#picname").val(res.info);
                }
            }
        });
    });


</script>
@endsection
